home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1993 July / InfoMagic USENET CD-ROM July 1993.ISO / sources / misc / volume5 / nnscript < prev    next >
Encoding:
Internet Message Format  |  1989-02-03  |  6.0 KB

  1. Path: xanth!nic.MR.NET!hal!ncoast!allbery
  2. From: waynet@mongo.UUCP (Wayne Thompson)
  3. Newsgroups: comp.sources.misc
  4. Subject: v05i065: nnscript (wrapper for enscript)
  5. Keywords: enscript ADOBE postscript
  6. Message-ID: <33537@mongo.uucp>
  7. Date: 3 Dec 88 00:34:21 GMT
  8. Sender: allbery@ncoast.UUCP
  9. Reply-To: waynet@mongo.UUCP (Wayne Thompson)
  10. Organization: Sun Microsystems, Inc. - Mtn View, CA
  11. Lines: 189
  12. Approved: allbery@ncoast.UUCP
  13.  
  14. Posting-number: Volume 5, Issue 65
  15. Submitted-by: "Wayne Thompson" <waynet@mongo.UUCP>
  16. Archive-name: nnscript
  17.  
  18. [enscript appears to be a program for translating ASCII files into
  19. PostScript code for printing on a PS printer.  ++bsa]
  20.  
  21. If you don't have enscript(1-local) then ignore this (or file for future
  22. reference). Buggestions, comments. flames? welcome.
  23. Wayne
  24.  
  25. #! /bin/sh
  26. # This is a shell archive, meaning:
  27. # 1. Remove everything above the #! /bin/sh line.
  28. # 2. Save the resulting text in a file.
  29. # 3. Execute the file with /bin/sh (not csh) to create:
  30. #    nnscript
  31. # This archive created: Wed Nov 30 08:16:07 1988
  32. export PATH; PATH=/bin:/usr/bin:$PATH
  33. echo shar: "extracting 'nnscript'" '(4406 characters)'
  34. if test -f 'nnscript'
  35. then
  36.     echo shar: "will not over-write existing file 'nnscript'"
  37. else
  38. sed 's/^    X//' << \SHAR_EOF > 'nnscript'
  39.     X#! /bin/sh
  40.     X#
  41.     X#    @(#)nnscript        1.0 (sun!waynet) 11/29/88
  42.     X#
  43.     XPATHNAME=oculus:/HOME/waynet/bin/nnscript
  44.     X#
  45.     X# Author: Wayne Thompson
  46.     X#
  47.     X# Description:
  48.     X#     This is a wrapper for enscript(1).
  49.     X#         1. It prints an expanded Gaudy header. The header has
  50.     X#             a. full pathname
  51.     X#             b. file size in bytes
  52.     X#             c. user name in internet format
  53.     X#             d. '(folded)' if so
  54.     X#         2. It prints using the least number of sheets (within reason)
  55.     X#             by fooling with the number of columns, rotation, and font
  56.     X#             size.
  57.     X#         3. It prevents character lossage due to line length by
  58.     X#             fooling with the rotation, font size, and by folding as
  59.     X#             a last resort.
  60.     X#
  61.     X#     enscript - Line & Page lengths for various options w/Gaudy
  62.     X#
  63.     X#                font = Courier
  64.     X#     lnlen 2r      R       r               pglen   r       R
  65.     X#     f10   62c     90c     125c            f10     47l     64l
  66.     X#     f9    69c     101c    139c            f9      52l     70l
  67.     X#     f8    77c     113c    156c            f8      58l     78l
  68.     X#     f7    89c     129c    179c            f7      65l     88l
  69.     X#     f6                    209c
  70.     X#     f5                    250c
  71.     X#
  72.     X# Options:
  73.     X#     -s    Single column only.
  74.     X#     Anything that enscript understands.
  75.     X#
  76.     X# Files:
  77.     X#
  78.     X# Diagnostics:
  79.     X#
  80.     X# Dependencies:
  81.     X#     Above table applies only to Courier type face and Gaudy mode.
  82.     X#
  83.     X# Bugs:
  84.     X#     Each file is filtered through expand(1) and read by awk(1) to
  85.     X#         determine longest line, this can be slow for large files.
  86.     X#     A banner page is produced for each file.
  87.     X#
  88.     X
  89.     Xfont=Courier                        # mono space typeface
  90.     Xuser=${USER}@`hostname`
  91.     X
  92.     Xfor i
  93.     Xdo 
  94.     X    case $i in
  95.     X    -d) debug=true; shift;;
  96.     X    -s) sgl_col=true; shift;;            # single column
  97.     X    -*) hard_opts="${hard_opts} \"$i\""; shift;;# buffer opts
  98.     X    *)  break;;
  99.     X    esac
  100.     Xdone
  101.     X
  102.     Xfor file
  103.     Xdo
  104.     X    cd `dirname ${file}`
  105.     X    file=`basename ${file}`
  106.     X    pathname=`pwd`/${file}
  107.     X    if [ ! -f $pathname ]
  108.     X    then
  109.     X    echo "$pathname: No such file"
  110.     X    continue
  111.     X    fi
  112.     X
  113.     X    cmd=`expand ${file} | awk '
  114.     X    {
  115.     X        l = length ($0);
  116.     X        if (l > ll)
  117.     X        ll = l;                                # longest line in file
  118.     X    }
  119.     X
  120.     X    END {
  121.     X            opts = "-1Rf'"${font}"'10";        # default - 1col portrait 10pt
  122.     X        dp = int (NR / 64); if (NR % 64 > 0) dp++;    # pgs for default
  123.     X
  124.     X            if (ll > 179) {
  125.     X                cmd = "fold -176 '"${file}"' | ";
  126.     X        }
  127.     X        else {
  128.     X        cmd = "cat '"${file}"' | ";
  129.     X        }
  130.     X        cmd = cmd "enscript -GJ'"${file}"' ";
  131.     X
  132.     X            if (ll > 156) {
  133.     X                opts = "-1rf'"${font}"'7";            # 1col landscape 7pt
  134.     X        }
  135.     X            else if (ll > 139) {
  136.     X                opts = "-1rf'"${font}"'8";             # 1col landscape 8pt
  137.     X        }
  138.     X            else if (ll > 125) {
  139.     X                opts = "-1rf'"${font}"'9";             # 1col landscape 9pt
  140.     X        }
  141.     X            else if (ll > 113) {
  142.     X                opts = "-1rf'"${font}"'10";            # 1col landscape 10pt
  143.     X        }
  144.     X           else if (ll > 101) {
  145.     X                opts = "-1Rf'"${font}"'8";             # 1col portrait 8pt
  146.     X        }
  147.     X            else if (ll > 90) {
  148.     X                opts = "-1Rf'"${font}"'9";             # 1col portrait 9pt
  149.     X        }
  150.     X            else if (ll > 89) {
  151.     X                opts = "-1Rf'"${font}"'10";             # 1col portrait 10pt
  152.     X        }
  153.     X            else if (ll > 77 && ll < 90 && "'"${sgl_col}"'" == "") {
  154.     X        np = int (NR / 130); if (NR % 130 > 0) np++;
  155.     X        if (dp > np)
  156.     X                    opts = "-2rf'"${font}"'7";        # 2col landscape 7pt
  157.     X            }
  158.     X            else if (ll > 69 && "'"$sgl_col"'" == "") {
  159.     X        np = int (NR / 116); if (NR % 116 > 0) np++;
  160.     X        if (dp > np)
  161.     X                    opts = "-2rf'"${font}"'8";        # 2col landscape 8pt
  162.     X            }
  163.     X            else if (ll > 62 && "'"$sgl_col"'" == "") {
  164.     X        np = int (NR / 104); if (NR % 104 > 0) np++;
  165.     X        if (dp > np)
  166.     X                    opts = "-2rf'"${font}"'9";        # 2col landscape 9pt
  167.     X            }
  168.     X            else  if ("'"$sgl_col"'" == "") {
  169.     X        np = int (NR / 94); if (NR % 94 > 0) np++;
  170.     X        if (dp > np)
  171.     X                    opts = "2rf'"${font}"'10";       # 2col landscape 10pt
  172.     X            }
  173.     X
  174.     X        if ("'"${debug}"'" == "true") {
  175.     X        printf ("ll = %d, NR = %d ,dp = %d, np = %d, cmd = ",\
  176.     X             ll, NR, dp, np);
  177.     X        }
  178.     X        print cmd opts;
  179.     X    }
  180.     X    '`
  181.     X
  182.     X    size=`ls -l ${file} | awk '{ print $4 }'`
  183.     X    note=`echo ${cmd} | awk '/^fold/ { print " - (folded)"; }'`
  184.     X    header="${pathname}, ${size} bytes, ${user}${note}"
  185.     X
  186.     X    if [ -n "$debug" ]
  187.     X    then
  188.     X    echo ${cmd} -b\"${header}\" ${hard_opts}
  189.     X    else
  190.     X    echo -n "${pathname} "
  191.     X    eval ${cmd} -b\"${header}\" ${hard_opts}
  192.     X    fi
  193.     Xdone
  194. SHAR_EOF
  195. if test 4406 -ne "`wc -c < 'nnscript'`"
  196. then
  197.     echo shar: "error transmitting 'nnscript'" '(should have been 4406 characters)'
  198. fi
  199. chmod +x 'nnscript'
  200. fi
  201. exit 0
  202. #    End of shell archive
  203.